package com.waimai.db.dao.impl;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.waimai.db.dao.BaseDao;
import com.waimai.db.dao.ReceiveAddressDao;
import com.waimai.db.entity.ReceiveAddress;

@Repository
public class ReceiveAddressDaoImpl extends BaseDao implements ReceiveAddressDao{

	public ReceiveAddress findById(Integer addressId) {
		return (ReceiveAddress) getSession().get(ReceiveAddress.class, addressId);
	}
	
	public ReceiveAddress addAddress(ReceiveAddress address) {
		getSession().save(address);
		return address;
	}

	public ReceiveAddress updateAddress(ReceiveAddress address) {
		getSession().update(address);
		return address;
	}

	public ReceiveAddress deleteAddress(Integer addressId) {
		ReceiveAddress address = findById(addressId);
		getSession().delete(address);
		return address;
	}

	@SuppressWarnings("unchecked")
	public List<Map<String, Object>> getReceiveAddresses() {
		// TODO Auto-generated method stub
		String hql="select u.userId,u.userName,u.phone,u.balance,a.addressId,a.addressName from User u,ReceiveAddress a where u.userId=a.user.userId";
		return getSession().createQuery(hql).list();
	}

}
